﻿package com.mui.controls
{
    import __AS3__.vec.*;
    import com.gengine.core.*;
    import com.gengine.game.*;
    import com.gengine.global.*;
    import com.mui.utils.*;
    import flash.display.*;
    import flash.events.*;

    public class GSprite extends Sprite implements IFrUIContainer
    {
        private var _uiDisposeVec:Vector.<IDispose>;
        protected var _disposed:Boolean = true;
        protected var isDisposeRemoveSelf:Boolean = true;
        protected var _isHideDispose:Boolean = false;
        private var _isDisposed:Boolean;
        private var _isMouseOver:Boolean = false;
        private var _disposedTime:int;
        protected var _width:Number = 0;
        protected var _height:Number = 0;

        public function GSprite()
        {
            this._uiDisposeVec = new Vector.<IDispose>;
            this.configUI();
            return;
        }// end function

        public function get isHideDispose() : Boolean
        {
            return this._isHideDispose;
        }// end function

        public function set isHideDispose(param1:Boolean) : void
        {
            if (this._isHideDispose == param1)
            {
                return;
            }
            this._isHideDispose = param1;
            if (param1)
            {
                this.addEventListener(Event.ADDED_TO_STAGE, this.onAddToStageCreate);
                this.addEventListener(Event.REMOVED_FROM_STAGE, this.onRemoveFromStageDispose);
            }
            else
            {
                this.removeEventListener(Event.ADDED_TO_STAGE, this.onAddToStageCreate);
                this.removeEventListener(Event.REMOVED_FROM_STAGE, this.onRemoveFromStageDispose);
            }
            return;
        }// end function

        protected function pushUIToDisposeVec(param1:IDispose) : void
        {
            this._uiDisposeVec.push(param1);
            return;
        }// end function

        protected function onAddToStageCreate(event:Event) : void
        {
            this.createDisposedChildren();
            return;
        }// end function

        protected function onRemoveFromStageDispose(event:Event) : void
        {
            this.disposeChildren();
            if (buttonMode && this._isMouseOver)
            {
                this.hideMouseHand();
            }
            return;
        }// end function

        public function configEventListener(param1:String, param2:Function, param3:Boolean = false, param4:int = 0, param5:Boolean = false) : void
        {
            ObjEventListerTool.addObjEvent(this, param1, param2, param3);
            addEventListener(param1, param2, param3, param4, param5);
            return;
        }// end function

        override public function removeEventListener(param1:String, param2:Function, param3:Boolean = false) : void
        {
            ObjEventListerTool.removeObjEvent(this, param1, param2, param3);
            super.removeEventListener(param1, param2, param3);
            return;
        }// end function

        public function get isDisposed() : Boolean
        {
            return this._disposed;
        }// end function

        protected function configUI() : void
        {
            this.createDisposedChildren();
            return;
        }// end function

        public function dispose(param1:Boolean = true) : void
        {
            if (this._isDisposed && param1)
            {
                if (Global.isDebugModle)
                {
                    Alert.show("存在组件二次释放" + this.toString());
                }
                return;
            }
            if (this._disposedTime > 0 && param1)
            {
                if (Global.isDebugModle)
                {
                    Alert.show("disposeImpl处调用了dispose！！！" + this.toString());
                }
            }
            var _loc_2:String = this;
            var _loc_3:* = this._disposedTime + 1;
            _loc_2._disposedTime = _loc_3;
            this.graphics.clear();
            this.tabChildren = false;
            this.visible = true;
            this._isMouseOver = false;
            this.disposeChildren();
            ObjEventListerTool.delObjEvent(this);
            if (this.isDisposeRemoveSelf)
            {
                if (this.parent)
                {
                    this.parent.removeChild(this);
                }
                if (param1)
                {
                    UICompomentPool.disposeUICompoment(this);
                }
            }
            this._disposedTime = 0;
            return;
        }// end function

        protected function disposeChildren(param1:Boolean = true) : void
        {
            var _loc_2:IDispose = null;
            if (!this._disposed)
            {
                this._disposed = true;
                for each (_loc_2 in this._uiDisposeVec)
                {
                    
                    _loc_2.dispose(param1);
                }
                this._uiDisposeVec = new Vector.<IDispose>;
                this.disposeImpl(param1);
            }
            return;
        }// end function

        public function createDisposedChildren() : void
        {
            if (!this._disposed)
            {
                return;
            }
            this._disposed = false;
            this.createDisposedChildrenImpl();
            return;
        }// end function

        public function set isDisposed(param1:Boolean) : void
        {
            this._isDisposed = param1;
            return;
        }// end function

        protected function disposeImpl(param1:Boolean = true) : void
        {
            return;
        }// end function

        protected function createDisposedChildrenImpl() : void
        {
            this.mouseEnabled = false;
            this.mouseChildren = true;
            this.tabChildren = false;
            return;
        }// end function

        public function setSize(param1:Number, param2:Number) : void
        {
            this._width = param1;
            this._height = param2;
            Global.instance.callLater(this.updateView);
            return;
        }// end function

        protected function updateView() : void
        {
            return;
        }// end function

        override public function get width() : Number
        {
            if (this._width)
            {
                return this._width;
            }
            return super.width;
        }// end function

        override public function set width(param1:Number) : void
        {
            if (this._width == param1)
            {
                return;
            }
            this.setSize(param1, this.height);
            return;
        }// end function

        override public function get height() : Number
        {
            if (this._height)
            {
                return this._height;
            }
            return super.height;
        }// end function

        override public function set buttonMode(param1:Boolean) : void
        {
            super.buttonMode = param1;
            if (param1)
            {
                this.configEventListener(MouseEvent.MOUSE_OVER, this.showMouseHand);
                this.configEventListener(MouseEvent.MOUSE_OUT, this.hideMouseHand);
            }
            else
            {
                this.removeEventListener(MouseEvent.MOUSE_OVER, this.showMouseHand);
                this.removeEventListener(MouseEvent.MOUSE_OUT, this.hideMouseHand);
            }
            return;
        }// end function

        protected function showMouseHand(event:MouseEvent) : void
        {
            if (this.mouseEnabled)
            {
                this._isMouseOver = true;
            }
            return;
        }// end function

        protected function hideMouseHand(event:MouseEvent = null) : void
        {
            this._isMouseOver = false;
            return;
        }// end function

        override public function set height(param1:Number) : void
        {
            if (this._height == param1)
            {
                return;
            }
            this.setSize(this.width, param1);
            return;
        }// end function

        public function move(param1:Number, param2:Number) : void
        {
            this.x = param1;
            this.y = param2;
            return;
        }// end function

    }
}
